package org.linlinjava.litemall.admin.controller.giftcards;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.LitemallGiftCardClassification;
import org.linlinjava.litemall.db.service.LitemallGiftCardClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.net.UnknownHostException;

/**
 * 管理礼品卡分类控制器
 *
 * @author yliyun
 * @description：TODO
 * @date 2024/04/26
 */
@Api(tags = "管理礼物卡分类控制器")
@RestController
@RequestMapping("/admin/giftcardClassification")
public class AdminGiftCardClassificationController {

    /**
     * litemall礼物卡分类服务
     */
    @Autowired
    private LitemallGiftCardClassificationService litemallGiftCardClassificationService;

    @GetMapping("/list")
    @LogAnno
    public Object list(LitemallGiftCardClassification litemallGiftCardClassification,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @Sort @RequestParam(defaultValue = "add_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {

        IPage<LitemallGiftCardClassification> cardClassificationIPage = litemallGiftCardClassificationService.querySelective(litemallGiftCardClassification, page, limit, sort, order);
        return ResponseUtil.okPage(cardClassificationIPage);
    }


    /**
     * 细节
     * @param id id
     * @return {@link Object}
     */
    @GetMapping("/detail")
    @LogAnno
    public Object detail(@NotNull Integer id) {
        return ResponseUtil.ok(litemallGiftCardClassificationService.findById(id));
    }

    /**
     * 创建
     * @param litemallGiftCardClassification
     * @return
     * @throws UnknownHostException
     */
    @PostMapping("/create")
    @LogAnno
    public Object create(@RequestBody @Valid LitemallGiftCardClassification litemallGiftCardClassification) throws UnknownHostException {
        litemallGiftCardClassificationService.add(litemallGiftCardClassification);
        return ResponseUtil.ok("礼物卡分类添加成功");
    }

    /**
     * 更新
     * @param litemallGiftCardClassification
     * @return
     */
    @PutMapping("/update")
    @LogAnno
    public Object update(@RequestBody LitemallGiftCardClassification litemallGiftCardClassification) {
        litemallGiftCardClassificationService.update(litemallGiftCardClassification);
        return ResponseUtil.ok("礼物卡分类更新成功");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    @LogAnno
    public Object delete(@NotNull Integer id) {
        litemallGiftCardClassificationService.deleteById(id);
        return ResponseUtil.ok("礼物分类删除成功");
    }




}
